package com.faradel.pharmapp.service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.faradel.pharmapp.entities.PharmaUser;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.faradel.pharmapp.dao.PharmaUserDAO;

@Service("userServiceImpl")
public class UserServiceImpl implements UserServiceInterface
{
    @Resource
    PharmaUserDAO pharmaUserDaoImpl;

    @Override
    @Transactional(readOnly = false)
    public void addUser(PharmaUser user)
    {
        getPharmaUserDaoImpl().save(user);
    }

    @Override
    @Transactional(readOnly = false)
    public void updateUser(PharmaUser user)
    {
        getPharmaUserDaoImpl().update(user);
    }

    @Override
    @Transactional(readOnly = false)
    public void deleteUser(PharmaUser user)
    {
        getPharmaUserDaoImpl().delete(user);
    }

    @Override
    @Transactional(readOnly = true)
    public PharmaUser getUserById(int id)
    {
        return getPharmaUserDaoImpl().get(id);
    }

    @Override
    @Transactional(readOnly = true)
    public List<PharmaUser> getAllUsers()
    {
        return getPharmaUserDaoImpl().selectAll();
    }

    @Override
    @Transactional(readOnly = true)
    public List<PharmaUser> getByColumns(Map<String, String> map)
    {
        return getPharmaUserDaoImpl().findByColumn(map);
    }

    public PharmaUserDAO getPharmaUserDaoImpl()
    {
        return pharmaUserDaoImpl;
    }

    public void setPharmaUserDaoImpl(PharmaUserDAO pharmaUserDaoImpl)
    {
        this.pharmaUserDaoImpl = pharmaUserDaoImpl;
    }
}
